package com.java.util.exception;

import org.springframework.core.MethodParameter;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import org.thymeleaf.exceptions.TemplateInputException;

import com.java.util.resp.BaseRespone;

@RestControllerAdvice 
public class ResponseAdvice implements ResponseBodyAdvice<Object> {
	
	 
	@ExceptionHandler(value = TemplateInputException.class)
    @ResponseBody
    public Object  handle(Exception e) {
		return BaseRespone.error(HttpStatus.NOT_FOUND.value(), "页面不存在");
    }

	@Override
	public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
		return false;
	}

	@Override
	public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
			Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
			ServerHttpResponse response) {
		return null;
	}
	 
	 
}
